﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public interface IPropertyChangeNotification
{
    event PropertyChangedEventHandler PropertyChanged;    
}

public class PersonEventArguments : EventArgs
{
    public string OldName { get; set; }
    public string NewName { get; set; }

    public PersonEventArguments(string oldName, string newName)
    {
        OldName = oldName;
        NewName = newName;
    }
}

public delegate void PropertyChangedEventHandler(object sender, PersonEventArguments args);

public class Person : IPropertyChangeNotification
{
    public Person(string firstName, string lastName, string gender, string birthDate)
    {
        this.FirstName = firstName;
        this.LastName = lastName;
        this.Gender = gender;
        this.BirthDate = birthDate;
        PropertyChanged += new PropertyChangedEventHandler(OnPropertyChanged);
    }

    private string firstName;
    private string lastName;
    private string gender;
    private string birthDate;

    public string FirstName
    {
        get { return this.firstName; }
        set
        {
            if (value != null)
            {
                if(PropertyChanged!=null)
                    PropertyChanged(this, new PersonEventArguments(FirstName,value));
                this.firstName = value;
            }
        }
    }
    public string LastName
    {
        get { return lastName; }
        set
        {
            if (value != null)
            {
                this.lastName = value;
            }
        }
    }
    public string Gender
    {
        get { return this.Gender; }
        set
        {
            this.gender = value;
        }
    }
    public string BirthDate
    {
        get { return this.birthDate; }
        set
        {
            if (value != null)
            {
                this.birthDate = value;
            }
        }
    }

    private void OnPropertyChanged(object sender, PersonEventArguments args)
    {
        Console.WriteLine("old name:{0}, new name:{1}",args.OldName, args.NewName);
    }

    public event PropertyChangedEventHandler PropertyChanged;
}
public class TestPerson
{
    public static void QjMiGo(object sender, PersonEventArguments args)
    {
        Console.WriteLine("qj mi go");
    }

    static void Main(string[] args)
    {
        Person person = new Person("Ivan", "Petrov", "Male", "21.12.2010");
        person.PropertyChanged += new PropertyChangedEventHandler(QjMiGo);
        Console.WriteLine("Enter new first name: ");
        string line = Console.ReadLine();
        person.FirstName = line;
    }
}

